package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.api.domain.Question;
import cn.wolfcode.wolf2w.business.query.QuestionQuery;
import cn.wolfcode.wolf2w.business.service.IQuestionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 提问 Controller
 * 
 * @author hyz
 * @date 2024-08-13
 */
@RestController
//@RequestMapping("questions")
@RequestMapping("destinationDoubt")
@Api(value = "question问答控制器接口",description = "question资源控制器")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;
    /**
     * 提问详情
     */
    @ApiOperation(value = "提问详情",notes = "查询提问详情，并将内容和提问者信息返回")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id",dataType = "Long",required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "创建成功"),
            @ApiResponse(code = 401,message = "没登录"),
            @ApiResponse(code = 403,message = "没权限"),
            @ApiResponse(code = 404,message = "接口找不到"),
            @ApiResponse(code = 500,message = "服务器内部异常，请联系管理员"),
            @ApiResponse(code = 501,message = "接口业务异常")
    })
    @GetMapping("/detail/{id}")
    public R<Question> detail(@PathVariable Long id) {
//        Question question = questionService.getById(id);
        Question question = questionService.queryById(id);
        return R.ok(question);
    }
    /**
     * 提问 列表
     */
    @ApiOperation(value = "提问列表",notes = "查询提问列表，并将内容和提问者信息返回")

    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "创建成功"),
            @ApiResponse(code = 401,message = "没登录"),
            @ApiResponse(code = 403,message = "没权限"),
            @ApiResponse(code = 404,message = "接口找不到"),
            @ApiResponse(code = 500,message = "服务器内部异常，请联系管理员"),
            @ApiResponse(code = 501,message = "接口业务异常")
    })
//    @GetMapping("/query")
    @GetMapping("/page")
    public R<IPage<Question>> query(QuestionQuery qo) {
        IPage<Question> page = questionService.queryPage(qo);
        return R.ok(page);
    }


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @ApiOperation(value = "Feign接口",notes = "查询列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "创建成功"),
            @ApiResponse(code = 401,message = "没登录"),
            @ApiResponse(code = 403,message = "没权限"),
            @ApiResponse(code = 404,message = "接口找不到"),
            @ApiResponse(code = 500,message = "服务器内部异常，请联系管理员"),
            @ApiResponse(code = 501,message = "接口业务异常")
    })
    @GetMapping("/feign/list")
    public R<List<Question>> feignList() {
        return R.ok(questionService.list());
    }
    @ApiOperation(value = "Feign接口",notes = "根据id查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id",dataType = "Long",required = true)
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "创建成功"),
            @ApiResponse(code = 401,message = "没登录"),
            @ApiResponse(code = 403,message = "没权限"),
            @ApiResponse(code = 404,message = "接口找不到"),
            @ApiResponse(code = 500,message = "服务器内部异常，请联系管理员"),
            @ApiResponse(code = 501,message = "接口业务异常")
    })
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Question> feignGet(@PathVariable Long id) {
        return R.ok(questionService.getById(id));
    }
}
